Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(apigatewayv2): Lambda authorizer for WebSocket API #16886

Merged
merged 16 commits into from
Dec 14, 2021

Conversation

tmokmss
Copy link
Contributor

@tmokmss tmokmss commented Oct 9, 2021

closes #13869

By this PR, you will be able to enable WebSocket authorizer as the below code:

    const integration = new LambdaWebSocketIntegration({
      handler,
    });
    const authorizer = new WebSocketLambdaAuthorizer('Authorizer', authHandler);
    new WebSocketApi(stack, 'WebSocketApi', {
      connectRouteOptions: {
        integration,
        authorizer,
      },
    });

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Oct 9, 2021

@tmokmss tmokmss changed the title feat(apigatewayv2): websocket authorizer feat(apigatewayv2): Lambda authorizer for WebSocket API Oct 9, 2021
@peterwoodworth peterwoodworth changed the title feat(apigatewayv2): Lambda authorizer for WebSocket API feat(apigatewayv2): Lambda authorizer for WebSocket API Oct 21, 2021
@github-actions github-actions bot added the @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 label Oct 21, 2021
@Dzhuneyt
Copy link
Contributor

This is perfect! Exactly what I need right now. I was planning to start a PR for myself.

Any chance we can prioritize this?

@nija-at nija-at added effort/medium Medium work item – several days of effort p2 labels Nov 5, 2021
@nija-at nija-at removed their assignment Nov 5, 2021
@otaviomacedo otaviomacedo self-assigned this Dec 13, 2021
'$request.header.Authorization',
],
type: WebSocketAuthorizerType.LAMBDA,
authorizerName: this.props.authorizerName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fall back to the new id constructor arg.

/**
* The name of the authorizer
*/
readonly authorizerName: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make this API consistent with HttpLambdaAuthorizer/HttpLambdaAuthorizerProps:

  1. Move handler to the constructor of WebSocketLambdaAuthorizer.
  2. Pass an id to the constructor of WebSocketLambdaAuthorizer.

const id = this.props.authorizerName;

this.webSocketApi = options.route.webSocketApi;
this.authorizer = new WebSocketAuthorizer(options.scope, id, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you add the new id constructor arg, replace id with this.id.

@tmokmss tmokmss marked this pull request as draft December 14, 2021 13:43
@mergify mergify bot dismissed otaviomacedo’s stale review December 14, 2021 13:44

Pull request has been modified.

@tmokmss tmokmss marked this pull request as ready for review December 14, 2021 14:46
@tmokmss
Copy link
Contributor Author

tmokmss commented Dec 14, 2021

@otaviomacedo
Hi, thanks for the review. I fixed the API to be more consistent with httpApi.
Also I updated README.md for apigatewayv2-authorizers. I'd appreciate if you could review again when you get a chance.

Copy link
Contributor

@otaviomacedo otaviomacedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@mergify
Copy link
Contributor

mergify bot commented Dec 14, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 6e88ddf
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 67cce37 into aws:master Dec 14, 2021
@mergify
Copy link
Contributor

mergify bot commented Dec 14, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@tmokmss tmokmss deleted the websocket_authorizer2 branch December 15, 2021 02:31
mergify bot pushed a commit that referenced this pull request Jan 7, 2022
… `WebSocketLambdaAuthorizer` (#18315)

We introduced `WebSocketLambdaAuthorizer` in #16886 with an incorrect default `identitySource`, according to these [docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-authorizer.html#cfn-apigatewayv2-authorizer-identitysource). The result is that using the default `identitySource` results in a deploy-time failure.

This PR fixes the error and adds documentation for the syntax for all `identitySource` possibilities.

I can confirm that this default successfully passes `cdk deploy` on my local app.

Fixes #18307. 

BREAKING CHANGE: `WebSocketLambdaAuthorizerProps.identitySource` default changes from `['$request.header.Authorization']` to `['route.request.header.Authorization']`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
closes aws#13869

By this PR, you will be able to enable WebSocket authorizer as the below code:

```ts
    const integration = new LambdaWebSocketIntegration({
      handler,
    });
    const authorizer = new WebSocketLambdaAuthorizer('Authorizer', authHandler);
    new WebSocketApi(stack, 'WebSocketApi', {
      connectRouteOptions: {
        integration,
        authorizer,
      },
    });
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
… `WebSocketLambdaAuthorizer` (aws#18315)

We introduced `WebSocketLambdaAuthorizer` in aws#16886 with an incorrect default `identitySource`, according to these [docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-authorizer.html#cfn-apigatewayv2-authorizer-identitysource). The result is that using the default `identitySource` results in a deploy-time failure.

This PR fixes the error and adds documentation for the syntax for all `identitySource` possibilities.

I can confirm that this default successfully passes `cdk deploy` on my local app.

Fixes aws#18307. 

BREAKING CHANGE: `WebSocketLambdaAuthorizerProps.identitySource` default changes from `['$request.header.Authorization']` to `['route.request.header.Authorization']`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(apigatewayv2): Allow to set Lambda authorizer for WebSocket API
5 participants